/**
 * 物质报买管理初始化
 */
var Buy = {
    id: "BuyTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Buy.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: 'id', field: 'id', visible: true, align: 'center', valign: 'middle'},
            {title: '报买单号',field: 'buyId', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '报买名称', field: 'buyName', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '报买日期', field: 'buyDate', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '报买数量', field: 'buyNumber', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '报买规格', field: 'buySpec', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '批量购买', field: 'buyLittle', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '负责人', field: 'buyPic', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '负责人电话', field: 'buyPicTel', visible: true, align: 'center', valign: 'middle', sortable: true},
            {title: '审核人', field: 'auditPersion', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '是否（审核）通过', field: 'auditPass', visible: true, align: 'center', valign: 'middle',sortable: true},
            {title: '审核意见', field: 'auditOpinoin', visible: true, align: 'center', valign: 'middle',sortable: true}
    ];
};

/**
 * 检查是否选中
 */
Buy.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Buy.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加物质报买
 */
Buy.openAddBuy = function () {
    var index = layer.open({
        type: 2,
        title: '添加物质报买',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/buy/buy_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看物质报买详情
 */
Buy.openBuyDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '物质报买详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/buy/buy_update/' + Buy.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除物质报买
 */
Buy.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/buy/delete", function (data) {
            Feng.success("删除成功!");
            Buy.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("buyId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询物质报买列表
 */
Buy.search = function () {
    var queryData = {};
    queryData['condition'] = $("#condition").val();
    Buy.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = Buy.initColumn();
    var table = new BSTable(Buy.id, "/buy/list", defaultColunms);
    table.setPaginationType("client");
    Buy.table = table.init();
});
